var assert = require("assert");
var request = require('request');

var token = 'test';
var serviceUrl = 'http://localhost:3000/admin/';
var createUrl = serviceUrl + '?token=' + token;
var updateUrl;

describe('雇主测试', function () {
	it('新建', function(done) {
		// 提交正确数据
		var postCreate = function() {
			request.post(createUrl, function(err, res, body) {
				if (err) throw err;
				
				console.log('post create code : ', res.statusCode);
				console.log('post create body : ', body);
				assert.equal(200, res.statusCode, '新建返回状态错误');
				assert(body, '新建没有返回结果');
				var admin = JSON.parse(body);
				console.log('post create : %j', admin);
				updateUrl = serviceUrl + admin._id + '?token=' + token;
				done();
			}).form({
				name : 'test',
				password : 'test123',
				phone : '18600029714',
				roles : ['test']
			});
		};
		
		postCreate();
	});
	
	
	it('修改', function(done) {
		// 提交正确数据
		var putUpdate = function() {
			var createReq = request.put(updateUrl, function(err, res, body) {
				if (err) throw err;
				
				console.log('code : ', res.statusCode);
				console.log('body : ', body);
				assert.equal(200, res.statusCode, '返回状态错误');
				assert(body, '没有返回结果');
				
				done();
			}).form({
				password : '123123测试',
				roles : ['admin']
			});
		};
		
		putUpdate();
	});
	
});